package xiaoqi.springboot.boot.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/test")
public class    TestController {

    @RequestMapping("/url")
    public void test01(@RequestBody Map<String, Object> data) {


//        String serviceParams = Optional.ofNullable(data.get("payload")).map(Object::toString).orElse("");
        Optional<List> serviceParams = Optional.ofNullable((List)data.get("payload"));
        JSONArray.parseArray(JSON.toJSONString(data.get("payload")));


//        JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(data.get("payload")));

        System.out.println(data.get("payload"));
        System.out.println(serviceParams);
        if(serviceParams.isPresent()) {
            JSONArray payload = JSONArray.parseArray(JSON.toJSONString(serviceParams.get()));
            System.out.println(payload);
        }

        System.out.println(serviceParams);

        Object o = Optional.ofNullable(data.get("payload")).orElse("");
//        System.out.println(o);
        String jsonSTr = JSONObject.toJSONString(o);
        System.out.println(jsonSTr);
//        JSONObject jsonObject = JSONObject;
//        System.out.println(jsonObject);
//        JSONArray.parse
//        array.




    }
}
